<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>bidi_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_i18n_bidi_test.js.html">bidi_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.i18n.bidiTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.i18n.bidiTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.i18n.bidi&#39;);
<a name="line19"></a>goog.require(&#39;goog.i18n.bidi.Dir&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line21"></a>
<a name="line22"></a>var LRE = &#39;\u202A&#39;;
<a name="line23"></a>var RLE = &#39;\u202B&#39;;
<a name="line24"></a>var PDF = &#39;\u202C&#39;;
<a name="line25"></a>var LRM = &#39;\u200E&#39;;
<a name="line26"></a>var RLM = &#39;\u200F&#39;;
<a name="line27"></a>
<a name="line28"></a>function testToDir() {
<a name="line29"></a>  assertEquals(null, goog.i18n.bidi.toDir(null));
<a name="line30"></a>  assertEquals(null, goog.i18n.bidi.toDir(null, true));
<a name="line31"></a>
<a name="line32"></a>  assertEquals(goog.i18n.bidi.Dir.NEUTRAL,
<a name="line33"></a>      goog.i18n.bidi.toDir(goog.i18n.bidi.Dir.NEUTRAL));
<a name="line34"></a>  assertEquals(null, goog.i18n.bidi.toDir(0, true));
<a name="line35"></a>
<a name="line36"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line37"></a>      goog.i18n.bidi.toDir(goog.i18n.bidi.Dir.LTR));
<a name="line38"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line39"></a>      goog.i18n.bidi.toDir(goog.i18n.bidi.Dir.LTR, true));
<a name="line40"></a>  assertEquals(goog.i18n.bidi.Dir.LTR, goog.i18n.bidi.toDir(100));
<a name="line41"></a>  assertEquals(goog.i18n.bidi.Dir.LTR, goog.i18n.bidi.toDir(100, true));
<a name="line42"></a>  assertEquals(goog.i18n.bidi.Dir.LTR, goog.i18n.bidi.toDir(false));
<a name="line43"></a>  assertEquals(goog.i18n.bidi.Dir.LTR, goog.i18n.bidi.toDir(false, true));
<a name="line44"></a>
<a name="line45"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line46"></a>      goog.i18n.bidi.toDir(goog.i18n.bidi.Dir.RTL));
<a name="line47"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line48"></a>      goog.i18n.bidi.toDir(goog.i18n.bidi.Dir.RTL, true));
<a name="line49"></a>  assertEquals(goog.i18n.bidi.Dir.RTL, goog.i18n.bidi.toDir(-100));
<a name="line50"></a>  assertEquals(goog.i18n.bidi.Dir.RTL, goog.i18n.bidi.toDir(-100, true));
<a name="line51"></a>  assertEquals(goog.i18n.bidi.Dir.RTL, goog.i18n.bidi.toDir(true));
<a name="line52"></a>  assertEquals(goog.i18n.bidi.Dir.RTL, goog.i18n.bidi.toDir(true, true));
<a name="line53"></a>}
<a name="line54"></a>
<a name="line55"></a>function testIsRtlLang() {
<a name="line56"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;en&#39;));
<a name="line57"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;fr&#39;));
<a name="line58"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;zh-CN&#39;));
<a name="line59"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;fil&#39;));
<a name="line60"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;az&#39;));
<a name="line61"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;iw-Latn&#39;));
<a name="line62"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;iw-LATN&#39;));
<a name="line63"></a>  assert(!goog.i18n.bidi.isRtlLanguage(&#39;iw_latn&#39;));
<a name="line64"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;ar&#39;));
<a name="line65"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;AR&#39;));
<a name="line66"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;iw&#39;));
<a name="line67"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;he&#39;));
<a name="line68"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;fa&#39;));
<a name="line69"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;ckb&#39;));
<a name="line70"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;ar-EG&#39;));
<a name="line71"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;az-Arab&#39;));
<a name="line72"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;az-ARAB-IR&#39;));
<a name="line73"></a>  assert(goog.i18n.bidi.isRtlLanguage(&#39;az_arab_IR&#39;));
<a name="line74"></a>}
<a name="line75"></a>
<a name="line76"></a>function testIsLtrChar() {
<a name="line77"></a>  assert(goog.i18n.bidi.isLtrChar(&#39;a&#39;));
<a name="line78"></a>  assert(!goog.i18n.bidi.isLtrChar(&#39;\u05e0&#39;));
<a name="line79"></a>  var str = &#39;a\u05e0z&#39;;
<a name="line80"></a>  assert(goog.i18n.bidi.isLtrChar(str.charAt(0)));
<a name="line81"></a>  assert(!goog.i18n.bidi.isLtrChar(str.charAt(1)));
<a name="line82"></a>  assert(goog.i18n.bidi.isLtrChar(str.charAt(2)));
<a name="line83"></a>}
<a name="line84"></a>
<a name="line85"></a>function testIsRtlChar() {
<a name="line86"></a>  assert(!goog.i18n.bidi.isRtlChar(&#39;a&#39;));
<a name="line87"></a>  assert(goog.i18n.bidi.isRtlChar(&#39;\u05e0&#39;));
<a name="line88"></a>  var str = &#39;a\u05e0z&#39;;
<a name="line89"></a>  assert(!goog.i18n.bidi.isRtlChar(str.charAt(0)));
<a name="line90"></a>  assert(goog.i18n.bidi.isRtlChar(str.charAt(1)));
<a name="line91"></a>  assert(!goog.i18n.bidi.isRtlChar(str.charAt(2)));
<a name="line92"></a>}
<a name="line93"></a>
<a name="line94"></a>function testIsNeutralChar() {
<a name="line95"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;\u0000&#39;));
<a name="line96"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;\u0020&#39;));
<a name="line97"></a>  assert(!goog.i18n.bidi.isNeutralChar(&#39;a&#39;));
<a name="line98"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;!&#39;));
<a name="line99"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;@&#39;));
<a name="line100"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;[&#39;));
<a name="line101"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;`&#39;));
<a name="line102"></a>  assert(goog.i18n.bidi.isNeutralChar(&#39;0&#39;));
<a name="line103"></a>  assert(!goog.i18n.bidi.isNeutralChar(&#39;\u05e0&#39;));
<a name="line104"></a>}
<a name="line105"></a>
<a name="line106"></a>function testIsNeutralText() {
<a name="line107"></a>  assert(goog.i18n.bidi.isNeutralText(&#39;123&#39;));
<a name="line108"></a>  assert(!goog.i18n.bidi.isNeutralText(&#39;abc&#39;));
<a name="line109"></a>  assert(goog.i18n.bidi.isNeutralText(&#39;http://abc&#39;));
<a name="line110"></a>  assert(goog.i18n.bidi.isNeutralText(&#39; 123-()&#39;));
<a name="line111"></a>  assert(!goog.i18n.bidi.isNeutralText(&#39;123a456&#39;));
<a name="line112"></a>  assert(!goog.i18n.bidi.isNeutralText(&#39;123\u05e0456&#39;));
<a name="line113"></a>  assert(!goog.i18n.bidi.isNeutralText(&#39;&lt;input value=\u05e0&gt;123&amp;lt;&#39;, false));
<a name="line114"></a>  assert(goog.i18n.bidi.isNeutralText(&#39;&lt;input value=\u05e0&gt;123&amp;lt;&#39;, true));
<a name="line115"></a>}
<a name="line116"></a>
<a name="line117"></a>function testHasAnyLtr() {
<a name="line118"></a>  assert(!goog.i18n.bidi.hasAnyLtr(&#39;&#39;));
<a name="line119"></a>  assert(!goog.i18n.bidi.hasAnyLtr(&#39;\u05e0\u05e1\u05e2&#39;));
<a name="line120"></a>  assert(goog.i18n.bidi.hasAnyLtr(&#39;\u05e0\u05e1z\u05e2&#39;));
<a name="line121"></a>  assert(!goog.i18n.bidi.hasAnyLtr(&#39;123\t...  \n&#39;));
<a name="line122"></a>  assert(goog.i18n.bidi.hasAnyLtr(&#39;&lt;br&gt;123&amp;lt;&#39;, false));
<a name="line123"></a>  assert(!goog.i18n.bidi.hasAnyLtr(&#39;&lt;br&gt;123&amp;lt;&#39;, true));
<a name="line124"></a>}
<a name="line125"></a>
<a name="line126"></a>function testHasAnyRtl() {
<a name="line127"></a>  assert(!goog.i18n.bidi.hasAnyRtl(&#39;&#39;));
<a name="line128"></a>  assert(!goog.i18n.bidi.hasAnyRtl(&#39;abc&#39;));
<a name="line129"></a>  assert(goog.i18n.bidi.hasAnyRtl(&#39;ab\u05e0c&#39;));
<a name="line130"></a>  assert(!goog.i18n.bidi.hasAnyRtl(&#39;123\t...  \n&#39;));
<a name="line131"></a>  assert(goog.i18n.bidi.hasAnyRtl(&#39;&lt;input value=\u05e0&gt;123&#39;, false));
<a name="line132"></a>  assert(!goog.i18n.bidi.hasAnyRtl(&#39;&lt;input value=\u05e0&gt;123&#39;, true));
<a name="line133"></a>}
<a name="line134"></a>
<a name="line135"></a>function testEndsWithLtr() {
<a name="line136"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;a&#39;));
<a name="line137"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;abc&#39;));
<a name="line138"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;a (!)&#39;));
<a name="line139"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;a.1&#39;));
<a name="line140"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;http://www.google.com &#39;));
<a name="line141"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;\u05e0a&#39;));
<a name="line142"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39; \u05e0\u05e1a\u05e2\u05e3 a (!)&#39;));
<a name="line143"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39;\u202b\u05d0!\u202c\u200e&#39;));
<a name="line144"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;&#39;));
<a name="line145"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39; &#39;));
<a name="line146"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;1&#39;));
<a name="line147"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;\u05e0&#39;));
<a name="line148"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;\u05e0 1(!)&#39;));
<a name="line149"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;a\u05e0&#39;));
<a name="line150"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;a abc\u05e0\u05e1def\u05e2. 1&#39;));
<a name="line151"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39;\u200f\u202eArtielish\u202c\u200f&#39;));
<a name="line152"></a>  assert(!goog.i18n.bidi.endsWithLtr(&#39; \u05e0\u05e1a\u05e2 &amp;lt;&#39;, true));
<a name="line153"></a>  assert(goog.i18n.bidi.endsWithLtr(&#39; \u05e0\u05e1a\u05e2 &amp;lt;&#39;, false));
<a name="line154"></a>}
<a name="line155"></a>
<a name="line156"></a>function testEndsWithRtl() {
<a name="line157"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;\u05e0&#39;));
<a name="line158"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;\u05e0\u05e1\u05e2&#39;));
<a name="line159"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;\u05e0 (!)&#39;));
<a name="line160"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;\u05e0.1&#39;));
<a name="line161"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;http://www.google.com/\u05e0 &#39;));
<a name="line162"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;a\u05e0&#39;));
<a name="line163"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39; a abc\u05e0def\u05e3. 1&#39;));
<a name="line164"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39;\u200f\u202eArtielish\u202c\u200f&#39;));
<a name="line165"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;&#39;));
<a name="line166"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39; &#39;));
<a name="line167"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;1&#39;));
<a name="line168"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;a&#39;));
<a name="line169"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;a 1(!)&#39;));
<a name="line170"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;\u05e0a&#39;));
<a name="line171"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;\u202b\u05d0!\u202c\u200e&#39;));
<a name="line172"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39;\u05e0 \u05e0\u05e1ab\u05e2 a (!)&#39;));
<a name="line173"></a>  assert(goog.i18n.bidi.endsWithRtl(&#39; \u05e0\u05e1a\u05e2 &amp;lt;&#39;, true));
<a name="line174"></a>  assert(!goog.i18n.bidi.endsWithRtl(&#39; \u05e0\u05e1a\u05e2 &amp;lt;&#39;, false));
<a name="line175"></a>}
<a name="line176"></a>
<a name="line177"></a>function testGuardBracketInHtml() {
<a name="line178"></a>  var strWithRtl = &#39;asc \u05d0 (\u05d0\u05d0\u05d0)&#39;;
<a name="line179"></a>  assertEquals(&#39;asc \u05d0 &lt;span dir=rtl&gt;(\u05d0\u05d0\u05d0)&lt;/span&gt;&#39;,
<a name="line180"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl));
<a name="line181"></a>  assertEquals(&#39;asc \u05d0 &lt;span dir=rtl&gt;(\u05d0\u05d0\u05d0)&lt;/span&gt;&#39;,
<a name="line182"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl, true));
<a name="line183"></a>  assertEquals(&#39;asc \u05d0 &lt;span dir=ltr&gt;(\u05d0\u05d0\u05d0)&lt;/span&gt;&#39;,
<a name="line184"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl, false));
<a name="line185"></a>
<a name="line186"></a>  var strWithRtl2 = &#39;\u05d0 a (asc:))&#39;;
<a name="line187"></a>  assertEquals(&#39;\u05d0 a &lt;span dir=rtl&gt;(asc:))&lt;/span&gt;&#39;,
<a name="line188"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl2));
<a name="line189"></a>  assertEquals(&#39;\u05d0 a &lt;span dir=rtl&gt;(asc:))&lt;/span&gt;&#39;,
<a name="line190"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl2, true));
<a name="line191"></a>  assertEquals(&#39;\u05d0 a &lt;span dir=ltr&gt;(asc:))&lt;/span&gt;&#39;,
<a name="line192"></a>      goog.i18n.bidi.guardBracketInHtml(strWithRtl2, false));
<a name="line193"></a>
<a name="line194"></a>  var strWithoutRtl = &#39;a (asc) {{123}}&#39;;
<a name="line195"></a>  assertEquals(&#39;a &lt;span dir=ltr&gt;(asc)&lt;/span&gt; &lt;span dir=ltr&gt;{{123}}&lt;/span&gt;&#39;,
<a name="line196"></a>      goog.i18n.bidi.guardBracketInHtml(strWithoutRtl));
<a name="line197"></a>  assertEquals(&#39;a &lt;span dir=rtl&gt;(asc)&lt;/span&gt; &lt;span dir=rtl&gt;{{123}}&lt;/span&gt;&#39;,
<a name="line198"></a>      goog.i18n.bidi.guardBracketInHtml(strWithoutRtl, true));
<a name="line199"></a>  assertEquals(&#39;a &lt;span dir=ltr&gt;(asc)&lt;/span&gt; &lt;span dir=ltr&gt;{{123}}&lt;/span&gt;&#39;,
<a name="line200"></a>      goog.i18n.bidi.guardBracketInHtml(strWithoutRtl, false));
<a name="line201"></a>
<a name="line202"></a>}
<a name="line203"></a>
<a name="line204"></a>function testGuardBracketInText() {
<a name="line205"></a>  var strWithRtl = &#39;asc \u05d0 (\u05d0\u05d0\u05d0)&#39;;
<a name="line206"></a>  assertEquals(&#39;asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f&#39;,
<a name="line207"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl));
<a name="line208"></a>  assertEquals(&#39;asc \u05d0 \u200f(\u05d0\u05d0\u05d0)\u200f&#39;,
<a name="line209"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl, true));
<a name="line210"></a>  assertEquals(&#39;asc \u05d0 \u200e(\u05d0\u05d0\u05d0)\u200e&#39;,
<a name="line211"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl, false));
<a name="line212"></a>
<a name="line213"></a>  var strWithRtl2 = &#39;\u05d0 a (asc:))&#39;;
<a name="line214"></a>  assertEquals(&#39;\u05d0 a \u200f(asc:))\u200f&#39;,
<a name="line215"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl2));
<a name="line216"></a>  assertEquals(&#39;\u05d0 a \u200f(asc:))\u200f&#39;,
<a name="line217"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl2, true));
<a name="line218"></a>  assertEquals(&#39;\u05d0 a \u200e(asc:))\u200e&#39;,
<a name="line219"></a>      goog.i18n.bidi.guardBracketInText(strWithRtl2, false));
<a name="line220"></a>
<a name="line221"></a>  var strWithoutRtl = &#39;a (asc) {{123}}&#39;;
<a name="line222"></a>  assertEquals(&#39;a \u200e(asc)\u200e \u200e{{123}}\u200e&#39;,
<a name="line223"></a>      goog.i18n.bidi.guardBracketInText(strWithoutRtl));
<a name="line224"></a>  assertEquals(&#39;a \u200f(asc)\u200f \u200f{{123}}\u200f&#39;,
<a name="line225"></a>      goog.i18n.bidi.guardBracketInText(strWithoutRtl, true));
<a name="line226"></a>  assertEquals(&#39;a \u200e(asc)\u200e \u200e{{123}}\u200e&#39;,
<a name="line227"></a>      goog.i18n.bidi.guardBracketInText(strWithoutRtl, false));
<a name="line228"></a>
<a name="line229"></a>}
<a name="line230"></a>
<a name="line231"></a>function testEnforceRtlInHtml() {
<a name="line232"></a>  var str = &#39;&lt;div&gt; first &lt;br&gt; second &lt;/div&gt;&#39;;
<a name="line233"></a>  assertEquals(&#39;&lt;div dir=rtl&gt; first &lt;br&gt; second &lt;/div&gt;&#39;,
<a name="line234"></a>               goog.i18n.bidi.enforceRtlInHtml(str));
<a name="line235"></a>  str = &#39;first second&#39;;
<a name="line236"></a>  assertEquals(&#39;\n&lt;span dir=rtl&gt;first second&lt;/span&gt;&#39;,
<a name="line237"></a>               goog.i18n.bidi.enforceRtlInHtml(str));
<a name="line238"></a>}
<a name="line239"></a>
<a name="line240"></a>function testEnforceRtlInText() {
<a name="line241"></a>  var str = &#39;first second&#39;;
<a name="line242"></a>  assertEquals(RLE + &#39;first second&#39; + PDF,
<a name="line243"></a>               goog.i18n.bidi.enforceRtlInText(str));
<a name="line244"></a>}
<a name="line245"></a>
<a name="line246"></a>function testEnforceLtrInHtml() {
<a name="line247"></a>  var str = &#39;&lt;div&gt; first &lt;br&gt; second &lt;/div&gt;&#39;;
<a name="line248"></a>  assertEquals(&#39;&lt;div dir=ltr&gt; first &lt;br&gt; second &lt;/div&gt;&#39;,
<a name="line249"></a>               goog.i18n.bidi.enforceLtrInHtml(str));
<a name="line250"></a>  str = &#39;first second&#39;;
<a name="line251"></a>  assertEquals(&#39;\n&lt;span dir=ltr&gt;first second&lt;/span&gt;&#39;,
<a name="line252"></a>               goog.i18n.bidi.enforceLtrInHtml(str));
<a name="line253"></a>}
<a name="line254"></a>
<a name="line255"></a>function testEnforceLtrInText() {
<a name="line256"></a>  var str = &#39;first second&#39;;
<a name="line257"></a>  assertEquals(LRE + &#39;first second&#39; + PDF,
<a name="line258"></a>               goog.i18n.bidi.enforceLtrInText(str));
<a name="line259"></a>}
<a name="line260"></a>
<a name="line261"></a>function testNormalizeHebrewQuote() {
<a name="line262"></a>  assertEquals(&#39;\u05d0\u05f4&#39;, goog.i18n.bidi.normalizeHebrewQuote(&#39;\u05d0&quot;&#39;));
<a name="line263"></a>  assertEquals(&#39;\u05d0\u05f3&#39;, goog.i18n.bidi.normalizeHebrewQuote(&#39;\u05d0\&#39;&#39;));
<a name="line264"></a>  assertEquals(&#39;\u05d0\u05f4\u05d0\u05f3&#39;,
<a name="line265"></a>               goog.i18n.bidi.normalizeHebrewQuote(&#39;\u05d0&quot;\u05d0\&#39;&#39;));
<a name="line266"></a>}
<a name="line267"></a>
<a name="line268"></a>function testMirrorCSS() {
<a name="line269"></a>  var str = &#39;left:10px;right:20px&#39;;
<a name="line270"></a>  assertEquals(&#39;right:10px;left:20px&#39;,
<a name="line271"></a>               goog.i18n.bidi.mirrorCSS(str));
<a name="line272"></a>  str = &#39;border:10px 20px 30px 40px&#39;;
<a name="line273"></a>  assertEquals(&#39;border:10px 40px 30px 20px&#39;,
<a name="line274"></a>               goog.i18n.bidi.mirrorCSS(str));
<a name="line275"></a>}
<a name="line276"></a>
<a name="line277"></a>function testEstimateDirection() {
<a name="line278"></a>  assertEquals(goog.i18n.bidi.Dir.NEUTRAL,
<a name="line279"></a>               goog.i18n.bidi.estimateDirection(&#39;&#39;, false));
<a name="line280"></a>  assertEquals(goog.i18n.bidi.Dir.NEUTRAL,
<a name="line281"></a>               goog.i18n.bidi.estimateDirection(&#39; &#39;, false));
<a name="line282"></a>  assertEquals(goog.i18n.bidi.Dir.NEUTRAL,
<a name="line283"></a>               goog.i18n.bidi.estimateDirection(&#39;! (...)&#39;, false));
<a name="line284"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line285"></a>               goog.i18n.bidi.estimateDirection(&#39;All-Ascii content&#39;, false));
<a name="line286"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line287"></a>               goog.i18n.bidi.estimateDirection(&#39;-17.0%&#39;, false));
<a name="line288"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line289"></a>               goog.i18n.bidi.estimateDirection(&#39;http://foo/bar/&#39;, false));
<a name="line290"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line291"></a>               goog.i18n.bidi.estimateDirection(
<a name="line292"></a>                   &#39;http://foo/bar/?s=\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0&#39; +
<a name="line293"></a>                   &#39;\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0&#39; +
<a name="line294"></a>                   &#39;\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0\u05d0&#39;,
<a name="line295"></a>                   false));
<a name="line296"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line297"></a>               goog.i18n.bidi.estimateDirection(&#39;\u05d0&#39;, false));
<a name="line298"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line299"></a>               goog.i18n.bidi.estimateDirection(
<a name="line300"></a>                   &#39;9 \u05d0 -&gt; 17.5, 23, 45, 19&#39;, false));
<a name="line301"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line302"></a>               goog.i18n.bidi.estimateDirection(
<a name="line303"></a>                   &#39;http://foo/bar/ \u05d0 http://foo2/bar2/ &#39; +
<a name="line304"></a>                   &#39;http://foo3/bar3/&#39;, false));
<a name="line305"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line306"></a>               goog.i18n.bidi.estimateDirection(
<a name="line307"></a>                   &#39;\u05d0\u05d9\u05df \u05de\u05de\u05e9 &#39; +
<a name="line308"></a>                   &#39;\u05de\u05d4 \u05dc\u05e8\u05d0\u05d5\u05ea: &#39; +
<a name="line309"></a>                   &#39;\u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 &#39; +
<a name="line310"></a>                   &#39;\u05d4\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0&#39; +
<a name="line311"></a>                   &#39;\u05dd \u05d4\u05d9\u05d9\u05ea\u05d9 \u05de\u05e6&#39; +
<a name="line312"></a>                   &#39;\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9\u05dd&#39;, false));
<a name="line313"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line314"></a>               goog.i18n.bidi.estimateDirection(
<a name="line315"></a>                   &#39;\u05db\u05d0 - http://geek.co.il/gallery/v/2007-06&#39; +
<a name="line316"></a>                   &#39; - \u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 &#39; +
<a name="line317"></a>                   &#39;\u05dc\u05e8\u05d0\u05d5\u05ea: \u05dc\u05d0 \u05e6&#39; +
<a name="line318"></a>                   &#39;\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1 &#39; +
<a name="line319"></a>                   &#39;\u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9&#39; +
<a name="line320"></a>                   &#39;\u05d9 \u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 &#39; +
<a name="line321"></a>                   &#39;\u05e9\u05dd \u05d1\u05e2\u05d9\u05e7 \u05d4\u05e8&#39; +
<a name="line322"></a>                   &#39;\u05d1\u05d4 \u05d0\u05e0\u05e9\u05d9\u05dd. \u05de&#39; +
<a name="line323"></a>                   &#39;\u05d4 \u05e9\u05db\u05df - \u05d0\u05e4\u05e9\u05e8 &#39; +
<a name="line324"></a>                   &#39;\u05dc\u05e0\u05e6\u05dc \u05d0\u05ea \u05d4\u05d4 &#39; +
<a name="line325"></a>                   &#39;\u05d3\u05d6\u05de\u05e0\u05d5 \u05dc\u05d4\u05e1&#39; +
<a name="line326"></a>                   &#39;\u05ea\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 &#39; +
<a name="line327"></a>                   &#39;\u05ea\u05de\u05d5\u05e0\u05d5\u05ea \u05de\u05e9&#39; +
<a name="line328"></a>                   &#39;\u05e9\u05e2\u05d5\u05ea \u05d9\u05e9\u05e0\u05d5 &#39; +
<a name="line329"></a>                   &#39;\u05d9\u05d5\u05ea\u05e8 \u05e9\u05d9\u05e9 \u05dc&#39; +
<a name="line330"></a>                   &#39;\u05d9 \u05d1\u05d0\u05ea\u05e8&#39;, false));
<a name="line331"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line332"></a>               goog.i18n.bidi.estimateDirection(
<a name="line333"></a>                   &#39;CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc &#39; +
<a name="line334"></a>                   &#39;\u05de\u05d3\u05d9?&#39;, false));
<a name="line335"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line336"></a>               goog.i18n.bidi.estimateDirection(
<a name="line337"></a>                   &#39;Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. &#39; +
<a name="line338"></a>                   &#39;\u05e9\u05d0\u05dc\u05d5 \u05d0\u05d5\u05ea\u05d9 &#39; +
<a name="line339"></a>                   &#39;\u05de\u05d4 \u05d0\u05e0\u05d9 \u05e8\u05d5\u05e6&#39; +
<a name="line340"></a>                   &#39;\u05d4 \u05de\u05ea\u05e0\u05d4 \u05dc\u05d7\u05d2&#39;,
<a name="line341"></a>                   false));
<a name="line342"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line343"></a>               goog.i18n.bidi.estimateDirection(
<a name="line344"></a>                   &#39;17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc\u05d0 &#39; +
<a name="line345"></a>                   &#39;\u05d4\u05d9\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.&#39;,
<a name="line346"></a>                   false));
<a name="line347"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line348"></a>               goog.i18n.bidi.estimateDirection(
<a name="line349"></a>                   &#39;5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. &#39; +
<a name="line350"></a>                   &#39;\u05d4\u05e0\u05e9\u05d9\u05e7\u05d4&#39;, false));
<a name="line351"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line352"></a>               goog.i18n.bidi.estimateDirection(
<a name="line353"></a>                   &#39;\u05d4\u05d3\u05dc\u05ea http://www.google.com &#39; +
<a name="line354"></a>                   &#39;http://www.gmail.com&#39;, false));
<a name="line355"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line356"></a>               goog.i18n.bidi.estimateDirection(
<a name="line357"></a>                   &#39;\u200f\u202eArtielish\u202c\u200f&#39;));
<a name="line358"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line359"></a>               goog.i18n.bidi.estimateDirection(
<a name="line360"></a>                   &#39;\u05d4\u05d3\u05dc &lt;some quite nasty html mark up&gt;&#39;,
<a name="line361"></a>                   false));
<a name="line362"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line363"></a>               goog.i18n.bidi.estimateDirection(
<a name="line364"></a>                   &#39;\u05d4\u05d3\u05dc &lt;some quite nasty html mark up&gt;&#39;,
<a name="line365"></a>                   true));
<a name="line366"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line367"></a>               goog.i18n.bidi.estimateDirection(
<a name="line368"></a>                   &#39;\u05d4\u05d3\u05dc\u05ea &amp;amp; &amp;lt; &amp;gt;&#39;, false));
<a name="line369"></a>  assertEquals(goog.i18n.bidi.Dir.RTL,
<a name="line370"></a>               goog.i18n.bidi.estimateDirection(
<a name="line371"></a>                   &#39;\u05d4\u05d3\u05dc\u05ea &amp;amp; &amp;lt; &amp;gt;&#39;, true));
<a name="line372"></a>  assertEquals(goog.i18n.bidi.Dir.LTR,
<a name="line373"></a>               goog.i18n.bidi.estimateDirection(
<a name="line374"></a>                   &#39;foo/&lt;b&gt;\u05d0&lt;/b&gt;&#39;, true));
<a name="line375"></a>}
<a name="line376"></a>
<a name="line377"></a>var bidi_text = [];
<a name="line378"></a>
<a name="line379"></a>function testDetectRtlDirectionality() {
<a name="line380"></a>  InitializeSamples();
<a name="line381"></a>  for (var i = 0; i &lt; bidi_text.length; i++) {
<a name="line382"></a>    //alert(bidi_text[i].text);
<a name="line383"></a>    var is_rtl = goog.i18n.bidi.detectRtlDirectionality(bidi_text[i].text,
<a name="line384"></a>                                                        bidi_text[i].isHtml);
<a name="line385"></a>    if (is_rtl != bidi_text[i].isRtl) {
<a name="line386"></a>      var str = &#39;&quot;&#39; + bidi_text[i].text + &#39;&quot; should be &#39; +
<a name="line387"></a>                (bidi_text[i].isRtl ? &#39;rtl&#39; : &#39;ltr&#39;) + &#39; but detected as &#39; +
<a name="line388"></a>                (is_rtl ? &#39;rtl&#39; : &#39;ltr&#39;);
<a name="line389"></a>      alert(str);
<a name="line390"></a>    }
<a name="line391"></a>    assertEquals(bidi_text[i].isRtl, is_rtl);
<a name="line392"></a>  }
<a name="line393"></a>}
<a name="line394"></a>
<a name="line395"></a>
<a name="line396"></a>function SampleItem() {
<a name="line397"></a>  this.text = &#39;&#39;;
<a name="line398"></a>  this.isRtl = false;
<a name="line399"></a>}
<a name="line400"></a>
<a name="line401"></a>function InitializeSamples() {
<a name="line402"></a>  var item = new SampleItem;
<a name="line403"></a>  item.text = &#39;Pure Ascii content&#39;;
<a name="line404"></a>  item.isRtl = false;
<a name="line405"></a>  bidi_text.push(item);
<a name="line406"></a>
<a name="line407"></a>  item = new SampleItem;
<a name="line408"></a>  item.text = &#39;\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 &#39; +
<a name="line409"></a>      &#39;\u05dc\u05e8\u05d0\u05d5\u05ea: \u05dc\u05d0 &#39; +
<a name="line410"></a>      &#39;\u05e6\u05d9\u05dc\u05de\u05ea\u05d9 \u05d4\u05e8\u05d1\u05d4 &#39; +
<a name="line411"></a>      &#39;\u05d5\u05d2\u05dd \u05d0\u05dd \u05d4\u05d9\u05d9\u05ea\u05d9 &#39; +
<a name="line412"></a>      &#39;\u05de\u05e6\u05dc\u05dd, \u05d4\u05d9\u05d4 \u05e9\u05dd&#39;;
<a name="line413"></a>  item.isRtl = true;
<a name="line414"></a>  bidi_text.push(item);
<a name="line415"></a>
<a name="line416"></a>  item = new SampleItem;
<a name="line417"></a>  item.text = &#39;\u05db\u05d0\u05df - http://geek.co.il/gallery/v/2007-06 - &#39; +
<a name="line418"></a>      &#39;\u05d0\u05d9\u05df \u05de\u05de\u05e9 \u05de\u05d4 &#39; +
<a name="line419"></a>      &#39;\u05dc\u05e8\u05d0\u05d5\u05ea: &#39; +
<a name="line420"></a>      &#39;\u05dc\u05d0 \u05e6\u05d9\u05dc\u05de\u05ea\u05d9 &#39; +
<a name="line421"></a>      &#39;\u05d4\u05e8\u05d1\u05d4 \u05d5\u05d2\u05dd \u05d0\u05dd &#39; +
<a name="line422"></a>      &#39;\u05d4\u05d9\u05d9\u05ea\u05d9 \u05de\u05e6\u05dc\u05dd, &#39; +
<a name="line423"></a>      &#39;\u05d4\u05d9\u05d4 \u05e9\u05dd \u05d1\u05e2\u05d9\u05e7\u05e8 &#39; +
<a name="line424"></a>      &#39;\u05d4\u05e8\u05d1\u05d4 \u05d0\u05e0\u05e9\u05d9\u05dd. &#39; +
<a name="line425"></a>      &#39;\u05de\u05d4 \u05e9\u05db\u05df - \u05d0\u05e4\u05e9\u05e8 &#39; +
<a name="line426"></a>      &#39;\u05dc\u05e0\u05e6\u05dc \u05d0\u05ea &#39; +
<a name="line427"></a>      &#39;\u05d4\u05d4\u05d3\u05d6\u05de\u05e0\u05d5\u05ea &#39; +
<a name="line428"></a>      &#39;\u05dc\u05d4\u05e1\u05ea\u05db\u05dc \u05e2\u05dc \u05db\u05de\u05d4 &#39; +
<a name="line429"></a>      &#39;\u05ea\u05de\u05d5\u05e0\u05d5\u05ea &#39; +
<a name="line430"></a>      &#39;\u05de\u05e9\u05e2\u05e9\u05e2\u05d5\u05ea &#39; +
<a name="line431"></a>      &#39;\u05d9\u05e9\u05e0\u05d5\u05ea \u05d9\u05d5\u05ea\u05e8 &#39; +
<a name="line432"></a>      &#39;\u05e9\u05d9\u05e9 \u05dc\u05d9 \u05d1\u05d0\u05ea\u05e8&#39;;
<a name="line433"></a>  item.isRtl = true;
<a name="line434"></a>  bidi_text.push(item);
<a name="line435"></a>
<a name="line436"></a>  item = new SampleItem;
<a name="line437"></a>  item.text =
<a name="line438"></a>      &#39;CAPTCHA \u05de\u05e9\u05d5\u05db\u05dc\u05dc \u05de\u05d3\u05d9?&#39;;
<a name="line439"></a>  item.isRtl = true;
<a name="line440"></a>  bidi_text.push(item);
<a name="line441"></a>
<a name="line442"></a>
<a name="line443"></a>  item = new SampleItem;
<a name="line444"></a>  item.text = &#39;Yes Prime Minister \u05e2\u05d3\u05db\u05d5\u05df. &#39; +
<a name="line445"></a>      &#39;\u05e9\u05d0\u05dc\u05d5 \u05d0\u05d5\u05ea\u05d9 \u05de\u05d4 &#39; +
<a name="line446"></a>      &#39;\u05d0\u05e0\u05d9 \u05e8\u05d5\u05e6\u05d4 \u05de\u05ea\u05e0\u05d4 &#39; +
<a name="line447"></a>      &#39;\u05dc\u05d7\u05d2&#39;;
<a name="line448"></a>  item.isRtl = true;
<a name="line449"></a>  bidi_text.push(item);
<a name="line450"></a>
<a name="line451"></a>  item = new SampleItem;
<a name="line452"></a>  item.text = &#39;17.4.02 \u05e9\u05e2\u05d4:13-20 .15-00 .\u05dc\u05d0 &#39; +
<a name="line453"></a>      &#39;\u05d4\u05d9\u05d9\u05ea\u05d9 \u05db\u05d0\u05df.&#39;;
<a name="line454"></a>  item.isRtl = true;
<a name="line455"></a>  bidi_text.push(item);
<a name="line456"></a>
<a name="line457"></a>  item = new SampleItem;
<a name="line458"></a>  item.text = &#39;5710 5720 5730. \u05d4\u05d3\u05dc\u05ea. &#39; +
<a name="line459"></a>      &#39;\u05d4\u05e0\u05e9\u05d9\u05e7\u05d4&#39;;
<a name="line460"></a>  item.isRtl = true;
<a name="line461"></a>  bidi_text.push(item);
<a name="line462"></a>
<a name="line463"></a>  item = new SampleItem;
<a name="line464"></a>  item.text =
<a name="line465"></a>      &#39;\u05d4\u05d3\u05dc\u05ea http://www.google.com http://www.gmail.com&#39;;
<a name="line466"></a>  item.isRtl = true;
<a name="line467"></a>  bidi_text.push(item);
<a name="line468"></a>
<a name="line469"></a>  item = new SampleItem;
<a name="line470"></a>  item.text = &#39;&amp;gt;\u05d4&amp;lt;&#39;;
<a name="line471"></a>  item.isHtml = true;
<a name="line472"></a>  item.isRtl = true;
<a name="line473"></a>  bidi_text.push(item);
<a name="line474"></a>
<a name="line475"></a>  item = new SampleItem;
<a name="line476"></a>  item.text = &#39;&amp;gt;\u05d4&amp;lt;&#39;;
<a name="line477"></a>  item.isHtml = false;
<a name="line478"></a>  item.isRtl = false;
<a name="line479"></a>  bidi_text.push(item);
<a name="line480"></a>
<a name="line481"></a>}
</pre>


</body>
</html>
